<?php

class String
{

    public static function limit ($string, $limit, $code = true)
    {
        if (strlen($string) > $limit) {
            if ($code)
                $string = mb_substr($string, 0, $limit, 'UTF-8') . '...';
            else
                $string = substr($string, 0, $limit) . '...';
        }
        
        return nl2br($string);
    }

    public static function split ($string, $limit)
    {
        if (strlen($string) > $limit) {
            
            $data = array();
            $data[] = nl2br(mb_substr($string, 0, $limit));
            $data[] = nl2br(mb_substr($string, $limit));
            
            return $data;
        }
        
        return nl2br($string);
    }

    public static function split_word ($string, $limit)
    {
        return explode("\n", wordwrap(self::limit($string, $limit * 5), $limit, "\n"));
    }

}